package com.tuanda.app.customviewdemo.cavans;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by LiDongduo on 2018/9/20.
 */
public class DrawHistogramView extends View {

    private Paint mPaint;

    public DrawHistogramView(Context context) {
        this(context, null);
    }

    public DrawHistogramView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DrawHistogramView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(Color.parseColor("#516e78"));
        mPaint.setColor(Color.WHITE);
        canvas.drawLines(new float[]{
                50, 50, 50, 100,
                50, 100, 400, 100}, mPaint);
        mPaint.setColor(Color.GREEN);
        canvas.drawRect(55, 95, 105, 100, mPaint);
        canvas.drawRect(110, 92, 160, 100, mPaint);
        canvas.drawRect(165, 70, 215, 100, mPaint);
        canvas.drawRect(220, 60, 270, 100, mPaint);
        canvas.drawRect(275, 40, 325, 100, mPaint);
        canvas.drawRect(330, 80, 380, 100, mPaint);
        mPaint.setTextSize(12);
        mPaint.setColor(Color.WHITE);
        canvas.drawText("GB",75,112,mPaint);
        canvas.drawText("ICS",125,112,mPaint);
        canvas.drawText("JB",180,112,mPaint);
        canvas.drawText("KitKat",230,112,mPaint);
        canvas.drawText("L",300,112,mPaint);
        canvas.drawText("M",350,112,mPaint);
    }
}
